package com.sgb.kjwl.view.ui.activity.material.hall;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.apeng.permissions.EsayPermissions;
import com.apeng.permissions.OnPermission;
import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.chuanglan.shanyan_sdk.listener.OneKeyLoginListener;
import com.chuanglan.shanyan_sdk.listener.OpenLoginAuthListener;
import com.github.dfqin.grantor.PermissionListener;
import com.github.dfqin.grantor.PermissionsUtil;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.ScrollBoundaryDecider;
import com.sgb.alimaplibrary.MarkerEntity;
import com.sgb.alimaplibrary.widget.MapMarkerView;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.model.entity.pick.TenderAllListNewEntity;
import com.sgb.kjwl.view.event.special.QuickEntryEvent;
import com.sgb.kjwl.view.ui.adapter.pick.PickHallAllNewAdapter;
import com.sgb.kjwl.view.ui.quickentry.BackResultContentListener;
import com.sgb.kjwl.view.ui.quickentry.QuickEntryEntity;
import com.sgb.link.utils.PickCateType;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.GsonManager;
import com.sgb.kjwl.databinding.NewFragmentPickBiddingListBinding;
import com.sgb.kjwl.di.pick.DaggerPickFragComponent;
import com.sgb.kjwl.di.pick.PickFragModule;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.utils.ConfigUtils;
import com.sgb.link.utils.SizeUtils;
import com.sgb.kjwl.utils.TextViewUtils;
import com.sgb.kjwl.utils.TouchHelper;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.link.event.MaterialEvent;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickHallActivity3;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.adapter.pick.PickBidingAdapter;
import com.sgb.kjwl.view.widget.CommonCategoryFilterPopWindow;
import com.sgb.link.view.widget.PickCityPopWindow;
import com.sgb.kjwl.view.widget.PickHallBidingPopWindow;
import com.sgb.kjwl.view.widget.pick.PickChooseLeftDialog2;
import com.sgb.kjwl.view.widget.pick.PickMapBiddingPopWindow;
import com.sgb.kjwl.view.widget.pick.PickPopWindowView;
import com.sgb.zhaocai.utils.PickCopyUtils;
import com.sgb.zhaocai.utils.PickUtil;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.mmkvutil.CacheMarker;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.PickSelectTextEntity;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.areapopup.GoodsSourceLocationEntity;
import com.swgk.core.view.areapopup.ThreeLevelAreaWindow;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 需求大厅--竞价集购
 */
public class NewPickBiddingListFragment extends AppLazyFragment implements PickChooseLeftDialog2.DialogCallBackImpl {

    @Inject
    NewPickBiddingModel viewModel;
    NewFragmentPickBiddingListBinding binding;

    private PickHallAllNewAdapter pickingAdapter;

    private PickCityPopWindow pickDistancePopWindow;
    private ThreeLevelAreaWindow mAddressPop;
    private PickHallBidingPopWindow pickMoneyPopWindow;
    private CommonCategoryFilterPopWindow categoryFilterPopWindow;
    private PickMapBiddingPopWindow pickMapBiddingPopWindow;
    private PickHallBidingPopWindow pickSortPopWindow;
    private PickHallBidingPopWindow pickTabLayoutPopWindow;
    private PickSelectEntity all;

    private List<PickSelectEntity> typeDatas = new ArrayList<>();
    private List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> categoryDatas = new ArrayList<>();
    private List<BiddingEntity> biddingListEntityMapList = new ArrayList<>();
    private List<PickSelectEntity> sortData = new ArrayList<>();
    private List<PickSelectEntity> tabTypeList = new ArrayList<>();

    //省
    private String areacode;
    private String areaName;
    //招标类型
    private String tenderTypeNo;
    //地区
    private String cityNo;
    //类型
    private String typeNo;
    //规模
    private String price;
    private String priceName = "";
    //状态
    private String statusNo;
    //时间
    private String time;
    //搜索关键字
    private String searchName = "";
    //排序类型
    private String sortType = "1";
    private String sortTypeName;
    private InputMethodManager im;
    private String goodsType;
    private String goodsTypeName;

    private String distance = "1000"; //距离筛选字段
    private String distanceName;
    private boolean isMap = true;
    private Double latitude; //纬度
    private Double longitude; //经度
    List<MarkerEntity> markerEntityList = new ArrayList<>();
    private boolean isHandLocation = false; //手动定位
    private boolean isLocation = false; //重新定位
    private int tabPosition = 0;
    //1-从商品需求大厅进 0-商品首页进  2-招采首页的直接竞价  3-招标大厅，招标公告-直接竞价  4-招采-企业网站-需求公告-招采需求-直接竞价
    public static final String FROM_WHERE = "FROM_WHERE";

    private boolean isUpDragging = true;

    private AppBarLayout.LayoutParams layoutParams;
    private boolean isAppBarExpended = false;
    private static final String TGA = "NewPickSigningUpListFragment";
    private boolean isParentAppBarCollapsed = false;
    private LinearLayoutManager layoutManager;
    private boolean isSearching = false;
    private int tabTypePosition;
    private boolean isDialogData = false;
    private boolean isEmpty = false;   //列表数据是否为空

    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> scrData;
    private String comNo;

    private boolean isEnableLoadMore = false; //是否可以上拉加载
    //是否是展开的筛选栏，默认展开
    private boolean mIsExpand = true;
    //手势监听帮助类
    private TouchHelper mTouchHelper;
    private boolean isFirstEnter = false;

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerPickFragComponent.builder()
                .appComponent(appComponent)
                .pickFragModule(new PickFragModule(this))
                .build()
                .inject(this);
    }

    public static NewPickBiddingListFragment newInstance(String fromWhere) {
        NewPickBiddingListFragment fragment = new NewPickBiddingListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FROM_WHERE, fromWhere);
        fragment.setArguments(bundle);
        return fragment;
    }

    public static NewPickBiddingListFragment newInstance(String fromWhere, String comNo) {
        NewPickBiddingListFragment fragment = new NewPickBiddingListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FROM_WHERE, fromWhere);
        bundle.putString("comNo", comNo);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.new_fragment_pick_bidding_list, container, false);
        binding.mMapView.initMap(savedInstanceState, getLifecycle(), 30, new MapMarkerView.CallBack() {
            @Override
            public void onLocation(Double lat, Double Log, String string) {
                binding.tvAddressName.setText(string);
                isHandLocation = false;
                latitude = lat;
                longitude = Log;
                binding.mMapView.mapMarkerTools.setMyLocation(latitude, longitude, R.drawable.pick_location);
                initFilterData();
                if (isLocation) {
                    binding.relNoMap.setVisibility(View.GONE);
                    binding.relLocation.setVisibility(View.VISIBLE);
                    isLocation = false;
                }

            }

            @Override
            public void onMarkerClick(int pos, String title) {
            }

            @Override
            public void onMarkerClick(int pos, String title, Marker marker) {
                super.onMarkerClick(pos, title, marker);
                setMarkerBig(marker.getTitle());
                showMapPopWindow(pos);
            }
        });

        return binding.getRoot();
    }


    private void init() {
        //scrollview 和 Map嵌套产生的滑动冲突解决
        binding.mapContainer.setScrollView(binding.scrollview);

        if ("1".equals(getArguments().get(FROM_WHERE))) {
            binding.topLayout.includeLayout.setVisibility(View.VISIBLE);
            binding.topLayout.ivBack.setVisibility(View.GONE);
            binding.topLayout.liuhaiStatusView.setVisibility(View.GONE);
            binding.tabLayout.setVisibility(View.GONE);
            binding.lineTabType.setVisibility(View.VISIBLE);
        } else if ("0".equals(getArguments().get(FROM_WHERE))) {
            binding.topLayout.includeLayout.setVisibility(View.GONE);
            binding.topLayout.ivBack.setVisibility(View.GONE);
            binding.topLayout.liuhaiStatusView.setVisibility(View.GONE);
            binding.tabLayout.setVisibility(View.GONE);
            binding.lineTabType.setVisibility(View.VISIBLE);
        } else if ("2".equals(getArguments().get(FROM_WHERE))) {
            binding.topLayout.includeLayout.setVisibility(View.VISIBLE);
            binding.topLayout.ivBack.setVisibility(View.VISIBLE);
            binding.topLayout.liuhaiStatusView.setVisibility(View.VISIBLE);
            binding.tabLayout.setVisibility(View.VISIBLE);
            binding.lineTabType.setVisibility(View.GONE);
        } else if ("3".equals(getArguments().get(FROM_WHERE))) {
            binding.topLayout.includeLayout.setVisibility(View.GONE);
            binding.topLayout.ivBack.setVisibility(View.GONE);
            binding.topLayout.liuhaiStatusView.setVisibility(View.GONE);
            binding.tabLayout.setVisibility(View.VISIBLE);
            binding.lineTabType.setVisibility(View.GONE);
        } else if ("4".equals(getArguments().get(FROM_WHERE))) {
            binding.topLayout.includeLayout.setVisibility(View.GONE);
            binding.recyclerView.setVisibility(View.VISIBLE);
            binding.mlFilterRoot.setVisibility(View.GONE);
        }
        comNo = getArguments().getString("comNo");
        initChooseDialog();
        binding.topLayout.etView.setTextColor(this.getResources().getColor(R.color.color_tab_one));

        // 金额
        pickMoneyPopWindow = new PickHallBidingPopWindow(getActivity());
        pickMoneyPopWindow.setBgView(binding.grayLayout);
        pickMoneyPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_MONEY, (Integer) key3);
                initFilterData();
            }
        });
        pickMoneyPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_MONEY);
                updateChooseTextStatus(binding.tvMoney, value > 0 ? 1 : 0, priceName);
            }
        });

        binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                tabPosition = tab.getPosition();
                typeNo = typeDatas.get(tab.getPosition()).getNo();
                showChooseView(tabPosition);
                if (tabPosition == 0 || tabPosition == (typeDatas.size() - 1)) {
                    if (tabPosition == (typeDatas.size() - 1)) {
                        binding.tvCategory.setVisibility(View.GONE);
                    }
                    binding.lineTabType.setVisibility(View.GONE);
                    initFilterData();
                } else {
                    resetCategoryFilterPopWindow();
                    binding.tabLayoutType.setTabRippleColor(ColorStateList.valueOf(getContext().getResources().getColor(R.color.translucent)));
                    binding.lineTabType.setVisibility(View.VISIBLE);
                    binding.tvCategory.setVisibility(View.GONE);
                    mFilters.put(PickCateType.TYPE_CATEGORY_0, 0);
                    mFilters.put(PickCateType.TYPE_CATEGORY_1, 0);
                    mFilters.put(PickCateType.TYPE_CATEGORY_2, 0);
                }

                if (tabPosition == 0) {
                    typeNo = "0";
                }
                clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
                clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
//                loadData(mData, mFilters);

                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item);
                    ImageView imageView = tab.getCustomView().findViewById(R.id.image_tab_item);
                    PickCopyUtils.setImageResources(tabPosition, imageView, true, getContext());
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    tabSelect.setTextColor(getResources().getColor(R.color.APPTabColor));
                    tabSelect.invalidate();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item);
                    ImageView imageView = tab.getCustomView().findViewById(R.id.image_tab_item);
                    PickCopyUtils.setImageResources(tabPosition, imageView, false, getContext());
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    tabSelect.setTextColor(getResources().getColor(R.color.color_tab_one));
                    tabSelect.invalidate();
                }
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }

        });

        binding.tabLayoutType.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                tabTypePosition = tab.getPosition();
                if (tabTypePosition == 0) {
                    binding.tvCategory.setVisibility(View.GONE);
                } else {
                    List<PickSelectEntity<List<PickSelectEntity>>> pickSelectEntities = categoryDatas.get(tabTypePosition).getChildren();
                    if (pickSelectEntities == null || pickSelectEntities.size() == 0) {
                        binding.tvCategory.setVisibility(View.GONE);
                    } else {
                        binding.tvCategory.setVisibility(View.VISIBLE);
                        if (!isDialogData) {
                            updateChooseStatus(PickCateType.TYPE_CATEGORY_0, 0);
                            mFilters.put(PickCateType.TYPE_CATEGORY_1, 0);
                            mFilters.put(PickCateType.TYPE_CATEGORY_2, 0);
                            List<PickSelectEntity> list2 = new ArrayList<>();
                            List<PickSelectEntity<List<PickSelectEntity>>> cate1 = categoryDatas.get(tabTypePosition).getChildren();
                            if (cate1 != null && cate1.size() > 0) {
                                list2.addAll(cate1);
                            }
                            refreshDataInfo(PickCateType.TYPE_CATEGORY_1, "", list2);
                        }
                    }
                }
                pickTabLayoutPopWindow.setDefItem(tabTypePosition);
                goodsType = tabTypeList.get(tabTypePosition).getNo();
                isDialogData = false;
                initFilterData();

                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item);
                    tabSelect.setBackgroundResource(R.drawable.search_new_blue_bg_10);
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    tabSelect.setTextColor(getResources().getColor(R.color.APPTabColor));
                    tabSelect.invalidate();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item);
                    tabSelect.setBackgroundResource(R.drawable.search_bg);
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    tabSelect.setTextColor(getResources().getColor(R.color.color_tab_one));
                    tabSelect.invalidate();
                }
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        categoryFilterPopWindow = new CommonCategoryFilterPopWindow(getActivity(), false);
        categoryFilterPopWindow.setBgView(binding.grayLayout);
        categoryFilterPopWindow.setResultListener(new CommonCategoryFilterPopWindow.Listener() {
            @Override
            public void setResultListener(String text, String result, String typeNo) {

            }

            @Override
            public void setResetResultListener() {
                addEntity(PickCateType.TYPE_CATEGORY_2, new ArrayList<>());
            }
        });
        categoryFilterPopWindow.setCategoryCallBack(new CommonCategoryFilterPopWindow.CategoryCallBack() {
            @Override
            public void resultPosition(String posName1, String posName2, String posName3, int pos1, int pos2, int pos3) {
                clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
                pos1 = tabTypePosition;
                mFilters.put(PickCateType.TYPE_CATEGORY_0, pos1);
                if (pos1 > 0) {
                    if (pos2 > 0) {
                        List<PickSelectEntity> list2 = new ArrayList<>();
                        List<PickSelectEntity<List<PickSelectEntity>>> cate1 = categoryDatas.get(pos1).getChildren();
                        if (cate1 != null && cate1.size() > 0) {
                            list2.addAll(cate1);
                        }
                        refreshDataInfo(PickCateType.TYPE_CATEGORY_1, "", list2);
                        updateChooseStatus(PickCateType.TYPE_CATEGORY_1, pos2);
                        if (pos3 > 0) {
                            List<PickSelectEntity> list3 = new ArrayList<>();
                            List<PickSelectEntity> cate2 = categoryDatas.get(pos1).getChildren().get(pos2).getChildren();
                            if (cate2 != null && cate2.size() > 0) {
                                list3.addAll(cate2);
                            }
                            refreshDataInfo(PickCateType.TYPE_CATEGORY_2, "", list3);
                            updateChooseStatus(PickCateType.TYPE_CATEGORY_2, pos3);
                        }
                    } else {
                        //重置
                        updateChooseStatus(PickCateType.TYPE_CATEGORY_0, 0);
                    }
                }
                initFilterData();
            }
        });
        categoryFilterPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int pos1 = getItemPos(PickCateType.TYPE_CATEGORY_0);
                updateChooseTextStatus(binding.tvCategory, pos1 > 0 ? 1 : 0, goodsTypeName);
            }
        });

        //类别二级
        pickTabLayoutPopWindow = new PickHallBidingPopWindow(getActivity());
        pickTabLayoutPopWindow.setBgView(binding.grayLayout);
        pickTabLayoutPopWindow.setOnResultClick((key1, key2, key3) -> {
            binding.tabLayoutType.getTabAt((int) key3).select();
            pickTabLayoutPopWindow.setDefItem((int) key3);
            goodsType = ((PickSelectEntity) key1).getNo();
            initFilterData();
        });
        pickTabLayoutPopWindow.setOnDisMissClick(() -> {
            binding.surveyView.setImageResource(R.drawable.btn_down);
        });

        //距离
        pickDistancePopWindow = new PickCityPopWindow(getActivity());
        pickDistancePopWindow.setBgView(binding.grayLayout);
        pickDistancePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_DISTANCE, (Integer) key3);
                initFilterData();
            }
        });
        pickDistancePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_DISTANCE);
                updateChooseTextStatus(binding.tvDistance, value > 0 ? 1 : 0, distanceName);
            }
        });

        //地图详情-竞价
        pickMapBiddingPopWindow = new PickMapBiddingPopWindow(getActivity(), 3, new PickMapBiddingPopWindow.CallBack() {
            @Override
            public void onMoreData(boolean more) {
                Log.e("api:", "倒数第二个 onMoreData");
                viewModel.getBiddingMapList(distance, typeNo, statusNo, price, true, searchName, goodsType, latitude, longitude);
            }

            @Override
            public void onItemClickAdapter(String id) {
                viewModel.getUrlSetting(id);
            }

            @Override
            public void onDismiss() {
                setMarkerBig(null);
            }

            @Override
            public void onShowPosition(int position) {
                showPositionMap(position, false);
            }

            @Override
            public void onReport(BiddingEntity biddingEntity) {
                viewModel.countByBusiness(biddingEntity.getId());
            }

            @Override
            public void onContactService(BiddingEntity biddingEntity) {
                if ("8".equals(biddingEntity.getState())) {
                    MToast.showToast(getContext(), "招标预告状态不可以发起交流");
                    return;
                }
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    if (!TextUtils.isEmpty(biddingEntity.getCustomerServiceContactsId())) {
                        viewModel.findCustomerServiceImAccount(biddingEntity.getCustomerServiceContactsId());
                    } else {
                        checkAllowDialog("招标方未设置客服人员，不支持交流。");
                    }
                }
            }

            @Override
            public void onInquireByLetter(BiddingEntity biddingEntity) {
                if ("8".equals(biddingEntity.getState())) {
                    MToast.showToast(getContext(), "招标预告状态不可以发起函询");
                    return;
                }
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    viewModel.checkAllowBidQuestion(biddingEntity.getId(), biddingEntity.getType() + "");
                }
            }

            @Override
            public void onLineUserFocus(BiddingEntity biddingEntity, int position) {
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                }else{
                    viewModel.editBid(biddingEntity.getId(), position);
                }
            }

        });
        //排序方式
        pickSortPopWindow = new PickHallBidingPopWindow(getActivity());
        pickSortPopWindow.setBgView(binding.grayLayout);
        pickSortPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                sortTypeName = ((PickSelectEntity) key1).getProjectscale();
                sortType = ((PickSelectEntity) key1).getNo();
                updateChooseTextStatus(binding.tvSort, (Integer) key3, sortTypeName);
                initFilterData();

            }
        });
        pickSortPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                updateChooseTextStatus(binding.tvSort, Integer.valueOf(sortType) == 1 ? 0 : 1, sortTypeName);
            }
        });
        binding.mMapView.getMap().setOnMapTouchListener(motionEvent -> {
            if (mTouchHelper == null) {
                mTouchHelper = TouchHelper.newInstance().addTouchListener(new TouchHelper.TouchListenerProxy() {
                    @Override
                    public void handlerUpTouch(float downX, float downY, float upX, float upY) {
                        //纵向滑动距离小于-100px
                        if (mIsExpand && upY - downY < -100) {
                            binding.mlFilterRoot.transitionToEnd();
                        }
                    }
                });
            }
            mTouchHelper.onTouch(null, motionEvent);
        });
        binding.mlFilterRoot.setTransitionListener(new MotionLayout.TransitionListener() {
            @Override
            public void onTransitionStarted(MotionLayout motionLayout, int i, int i1) {

            }

            @Override
            public void onTransitionChange(MotionLayout motionLayout, int i, int i1, float v) {

            }

            @Override
            public void onTransitionCompleted(MotionLayout motionLayout, int i) {
                mIsExpand = binding.mlFilterRoot.getProgress() == 0.0f;
                if (mIsExpand) {
                    binding.flExpandLine.setVisibility(View.VISIBLE);
                    binding.tvExpand.setText("收起筛选条件");
                    TextViewUtils.changeTextView(getActivity(), binding.tvExpand, R.drawable.btn_shop_up, false);
                } else {
                    binding.flExpandLine.setVisibility(View.GONE);
                    binding.tvExpand.setText("展开筛选条件");
                    TextViewUtils.changeTextView(getActivity(), binding.tvExpand, R.drawable.btn_shop_down, false);
                }
            }

            @Override
            public void onTransitionTrigger(MotionLayout motionLayout, int i, boolean b, float v) {
            }
        });
        initAddressPopup();
        setMapOrList(false);
    }

    private void initAddressPopup() {
        mAddressPop = new ThreeLevelAreaWindow(getActivity());
        mAddressPop.setMemberHeight();
        mAddressPop.setCitySingle();
        mAddressPop.setProvinceSingle();
        mAddressPop.setShowSimpleName(true);
        mAddressPop.setOnlyShowProAndCity(true);
        mAddressPop.setAllSingleSelect(true);
        mAddressPop.setThreeListIsGone(true);
        mAddressPop.setBgView(binding.grayLayout);
        mAddressPop.setOnResultClick(new ThreeLevelAreaWindow.OnResultClickProxy() {
            @Override
            protected void result(GoodsSourceLocationEntity entity) {
                clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
                if (!TextUtils.isEmpty(entity.getProvinceNo())) {
                    areaName = entity.getProvinceName();
                    areacode = entity.getProvinceNo();
                    cityNo = "";
                    if ("0".equals(areacode)) {
                        areaName = "地区";
                    }
                    updateChooseTextStatus(binding.tvArea, 1, areaName);
                    mFilters.put(PickCateType.TYPE_PROVINCE, mAddressPop.getProvincePosition());
                    if (!TextUtils.isEmpty(entity.getCityNo())) {
                        cityNo = entity.getCityNo();
                        areaName = entity.getCityName();
                        viewModel.getAddressCityData(scrData, entity.getProvinceNo(), PickCateType.TYPE_CITY);
                        updateChooseTextStatus(binding.tvArea, 1, areaName);
                        mFilters.put(PickCateType.TYPE_CITY, mAddressPop.getmCityPosition());
                    }
                } else {
                    mFilters.put(PickCateType.TYPE_PROVINCE, 0);  //重置
                    mFilters.put(PickCateType.TYPE_CITY, 0);
                    areaName = "地区";
                    areacode = "";
                    cityNo = "";
                    updateChooseTextStatus(binding.tvArea, 0, areaName);
                }
                initFilterData();
            }
        });
        mAddressPop.setOnDismissListener(() -> {
            int pos1 = getItemPos(PickCateType.TYPE_PROVINCE);
            updateChooseTextStatus(binding.tvArea, pos1 > 0 ? 1 : 0, areaName);
        });
    }

    public void setTvIsGz(int position) {
        pickMapBiddingPopWindow.updateFocus(position);
    }

    public void checkAllowDialog(String msg) {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tv_logout_cancel = view.findViewById(R.id.tv_logout_cancel);

        tv_logout_cancel.setVisibility(View.GONE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("提示");

        tv_message.setText(msg);

        //确定
        tv_logout_confirm.setOnClickListener(v -> roundCornerDialog.dismiss());
    }

    private void setMarkerBig(String title) {
        LatLng latLng = null;
        for (int i = 0; i < markerEntityList.size(); i++) {
            MarkerEntity markerEntity = markerEntityList.get(i);
            if (markerEntity.getTitle().equals(title)) {
                markerEntity.setBig(true);
            } else {
                markerEntity.setBig(false);
            }
            if (markerEntity.isBig()) {
//                if ("5".equals(markerEntity.getStatus())) {  //废标
//                    markerEntity.setIcon(R.mipmap.zhao_gray_big);
//                } else {
//                    markerEntity.setIcon(R.mipmap.ic_map_overlay_jing_big);
//                }
                markerEntity.setIcon(R.mipmap.ic_map_overlay_jing_big);
                latLng = markerEntity.getLatLng();
            } else {
//                if ("5".equals(markerEntity.getStatus())) {  //废标
//                    markerEntity.setIcon(R.mipmap.zhao_gray);
//                } else {
//                    markerEntity.setIcon(R.mipmap.ic_map_overlay_jing);
//                }
                markerEntity.setIcon(R.mipmap.ic_map_overlay_jing);
            }
        }
        binding.mMapView.setMarkerDataPick(markerEntityList, latLng);
    }

    /**
     * 地图和列表模式切换
     */
    private void setMapOrList(boolean isClick) {
        isMap = !isMap;
        if (false) { //当是地图，界面切换成列表样式
            setViewIsMap();
            if (latitude == null && longitude == null) {
                if (!isLocationEnabled()) {
                    binding.relLocation.setVisibility(View.GONE);
                    binding.relNoMap.setVisibility(View.VISIBLE);
                    return;
                }
                if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                        ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    binding.relLocation.setVisibility(View.GONE);
                    binding.relNoMap.setVisibility(View.VISIBLE);
                    return;
                }
            }
            if (isHandLocation) {  //手动定位成功
                if (isLocationEnabled()) {
                    latitude = null;
                    longitude = null;
                }
            }
        } else { //当是列表，将界面切换成地图模式
            mapBiddingPopWindowDismiss();
            setViewIsList();
            if (isClick) {
                binding.relNoMap.setVisibility(View.GONE);
            }

        }
        showChooseView(tabPosition);
        initFilterData();
    }

    /**
     * 将界面切换成地图模式
     */
    private void setViewIsMap() {
        binding.scrollview.smoothScrollTo(0, 0);
        binding.scrollview.scrollTo(0, 0);
        binding.swipeRefresh.setEnableLoadMore(false);
        binding.swipeRefresh.setEnableRefresh(false);
        binding.scrollview.setNestedScrollingEnabled(false);
        binding.imgBackTop.setVisibility(View.GONE);
        binding.frameLayoutList.setVisibility(View.GONE);
        if ("2".equals(getArguments().get(FROM_WHERE)) || "3".equals(getArguments().get(FROM_WHERE))) {
            binding.flExpand.setVisibility(View.VISIBLE);
            binding.flExpandLine.setVisibility(View.VISIBLE);
        }
        binding.mapContainer.setVisibility(View.VISIBLE);
        binding.relLocation.setVisibility(View.VISIBLE);
//        binding.ivListVsMak.setImageDrawable(getResources().getDrawable(R.drawable.bg_icon_list));
        if ("".equals(binding.tvAddressName.getText())) {
            binding.tvAddressName.setText(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.PROVINCE_ID, ""));
        }
        isFirstEnter = false;
    }

    /**
     * 将界面切换成列表模式
     */
    private void setViewIsList() {
        binding.swipeRefresh.setEnableLoadMore(true);
        binding.swipeRefresh.setEnableRefresh(true);
        binding.scrollview.setNestedScrollingEnabled(true);
        binding.mapContainer.setVisibility(View.GONE);
        if ("2".equals(getArguments().get(FROM_WHERE)) || "3".equals(getArguments().get(FROM_WHERE))) {
            binding.flExpand.setVisibility(View.GONE);
            binding.flExpandLine.setVisibility(View.GONE);
        }
        binding.relLocation.setVisibility(View.GONE);
        if (isEmpty) {
            binding.recyclerView.setVisibility(View.GONE);
            binding.emptyView.setVisibility(View.VISIBLE);
        } else {
            binding.recyclerView.setVisibility(View.VISIBLE);
            binding.emptyView.setVisibility(View.GONE);
        }
        binding.frameLayoutList.setVisibility(View.VISIBLE);
//        binding.ivListVsMak.setImageDrawable(getResources().getDrawable(R.drawable.bg_icon_map));
    }

    public void setTenderGoodsCategoryAllList(List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> datas) {
        categoryDatas.clear();
        categoryDatas.addAll(datas);
        if (categoryDatas.size() != 0) {
            categoryDatas.get(0).setCheck(true);
            List<PickSelectEntity> list = new ArrayList<>();
            list.addAll(categoryDatas);
            refreshDataInfo(PickCateType.TYPE_CATEGORY_0, "类别", list);
            tabTypeList.clear();
            binding.tabLayoutType.removeAllTabs();
            for (int i = 0; i < categoryDatas.size(); i++) {
                PickSelectEntity pickSelectEntity = new PickSelectEntity(categoryDatas.get(i).getNo(), categoryDatas.get(i).getProjectscale());
                tabTypeList.add(pickSelectEntity);
                binding.tabLayoutType.addTab(binding.tabLayoutType.newTab().setText(pickSelectEntity.getProjectscale()));

                binding.tabLayoutType.getTabAt(i).setCustomView(R.layout.tab_item_textview_pick);
                TextView tv = binding.tabLayoutType.getTabAt(i).getCustomView().findViewById(R.id.tv_tab_item);
                if (pickSelectEntity.getProjectscale().length() > 4) {
                    tv.setText(pickSelectEntity.getProjectscale().substring(0, 4) + "...");
                } else {
                    if (i == 0) {
                        tv.setBackgroundResource(R.drawable.search_new_blue_bg_10);
                        tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                        tv.setTextColor(getResources().getColor(R.color.APPTabColor));
                    }
                    tv.setText(pickSelectEntity.getProjectscale());
                }
            }
            binding.tabLayoutType.scrollTo(0, 0);
        }
    }

    private void resetCategoryFilterPopWindow() {
        clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
        getCategoryAllList();
    }

    private void getCategoryAllList() {
        viewModel.getTenderGoodsCategoryAllList(typeNo);
    }

    private void initFilterData() {
        if (isMap) {
            if (latitude == null || longitude == null) {
                return;
            }
            viewModel.getBiddingMapList(distance, typeNo, statusNo, price, false, searchName, goodsType, latitude, longitude);
        } else {
            viewModel.getBiddingList(cityNo, typeNo, statusNo, price, false, searchName, areacode, goodsType, sortType, comNo);
        }
    }

    private void initViewData() {
        binding.setViewModel(viewModel);
        binding.topLayout.rightView.setOnClickListener(this);
        binding.topLayout.rightView.setText("发布");
        binding.topLayout.tvSearch.setOnClickListener(this);
        binding.topLayout.tvSearch.setText("搜索");
        binding.tvMoney.setOnClickListener(this);
        binding.tvArea.setOnClickListener(this);
        binding.topLayout.etView.setOnClickListener(this);
        binding.topLayout.tvSearchDelete.setOnClickListener(this);
        binding.topLayout.tvSearchDelete.setVisibility(View.GONE);
        binding.topLayout.etView.setHint("搜索竞价名称、采购单位");
        binding.topLayout.ivBack.setOnClickListener(this);
        //新增类别
        binding.tvCategory.setOnClickListener(this);

        //地图列表切换按钮
//        binding.ivListVsMak.setOnClickListener(this);
        //距离筛选
        binding.tvDistance.setOnClickListener(this);
        binding.tvLocation.setOnClickListener(this);
        binding.handLocation.setOnClickListener(this);
        binding.getLocation.setOnClickListener(this);
        binding.imgBackTop.setOnClickListener(this);
        binding.ivChoose.setOnClickListener(this);
        binding.tvSort.setOnClickListener(this);
        binding.ivLocationRight.setOnClickListener(this);
        binding.surveyView.setOnClickListener(this);
        binding.ivQuickEntry.setOnClickListener(this);

        if (pickingAdapter == null) {
            pickingAdapter = new PickHallAllNewAdapter(getActivity(), null);
        }
        all = new PickSelectEntity();
        all.setNo("");
        all.setProjectscale("全部");
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.shape_list_divide2));
        binding.recyclerView.addItemDecoration(divider);
        layoutManager = new LinearLayoutManager(getActivity());
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(pickingAdapter);


        im = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

        if (getArguments() != null && "0".equals(getArguments().get(FROM_WHERE))) {
            binding.recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
//            binding.recyclerView.setPullRefreshEnabled(false);
            //initStickView();
        }

        binding.topLayout.etView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
        binding.topLayout.etView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (isSearching) return true;
                if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                    if (TextUtils.isEmpty(binding.topLayout.etView.getText().toString())) {
                        MToast.showToast(getContext(), "请输入搜索内容");
                        return true;
                    }
                    if (searchName.equals(binding.topLayout.etView.getText().toString())) {
                        MToast.showToast(getContext(), "请输入不同的搜索内容");
                        return true;
                    }
                    isSearching = true;
                    searchName = binding.topLayout.etView.getText().toString();
                    if (!TextUtils.isEmpty(searchName)) {
                        viewModel.getBiddingList(cityNo, typeNo, statusNo, price, false, searchName, areacode, goodsType, sortType, comNo);
                    }
                }
                return false;
            }
        });

        binding.topLayout.etView.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s)) {
                    binding.topLayout.tvSearchDelete.setVisibility(View.GONE);
                } else {
                    binding.topLayout.tvSearchDelete.setVisibility(View.VISIBLE);
                }
            }
        });

        int screenHeight = SizeUtils.getScreenHeight(getActivity());
        binding.scrollview.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                RecyclerView.LayoutManager layoutManager = binding.recyclerView.getLayoutManager();
                View view = layoutManager.findViewByPosition(0);
                if (view != null) {
                    int height = view.getMeasuredHeight();
                    int headHeight = screenHeight - binding.llContainer.getHeight();
                    int gonePosition = 10 - (headHeight / view.getHeight());
                    binding.imgBackTop.setVisibility((height * gonePosition) > scrollY ? View.GONE : View.VISIBLE);
                }
            }
        });

        binding.swipeRefresh.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                viewModel.getBiddingList(cityNo, typeNo, statusNo, price, true, searchName, areacode, goodsType, sortType, comNo);
//                binding.swipeRefresh.finishLoadMore(300);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                initFilterData();
                binding.swipeRefresh.finishRefresh(300);
            }
        });
        //解决 在实现 上拉加载更多 和 下拉刷新 时  遇到item不在顶端就执行了刷新的方法和数据item没有填满屏幕也执行了加载更多
        binding.swipeRefresh.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
            @Override
            public boolean canRefresh(View content) {
                if (binding.scrollview == null) return false;
                if (binding.scrollview.computeVerticalScrollOffset() == 0)
                    return true;
                return false;
            }

            @Override
            public boolean canLoadMore(View content) {
                if (binding.scrollview == null) return false;
                //获取recyclerView的高度
                binding.scrollview.getHeight();
                //整个View控件的高度
                int scrollRange = binding.scrollview.computeVerticalScrollRange();
                //当前屏幕之前滑过的距离
                int scrollOffset = binding.scrollview.computeVerticalScrollOffset();
                //当前屏幕显示的区域高度
                int scrollExtent = binding.scrollview.computeVerticalScrollExtent();
                int height = binding.scrollview.getHeight();
                if (height > scrollRange) {
                    return false;
                }
                if (isEnableLoadMore && scrollRange <= scrollOffset + scrollExtent) {
                    return true;
                }
                return false;
            }
        });

    }

    @Override
    protected void onLazyLoad() {
        initData();
    }

    @Override
    protected void initView() {
        super.initView();
        init();
        initViewData();
    }

    private void initData() {
        //类型
        viewModel.getFilterTypeData();
        //预算金额
        viewModel.getPriceData();
        //时间
        viewModel.getPickTimes();
        viewModel.getBidSortSelect();
        viewModel.getProvinceData(PickCateType.TYPE_PROVINCE);
        //距离筛选条件
        String[] strings = new String[]{"10", "20", "50", "100", "200", "500"};
        setDistanceDatas(strings);
    }

    /****
     * 初始化置顶监听
     */


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                getActivity().finish();
                break;
            case R.id.right_view:
                PickUtil.showBottomZhaoCaiDialog(getContext());
                break;
            case R.id.tv_money:
                showMoneyPopWindow();
                break;
            case R.id.tv_area:
                showProvincePopWindow();
                break;
            case R.id.tv_distance://距离筛选控件
                showDistancePopWindow();
                break;
            case R.id.tv_search:
                if (!TextUtils.isEmpty(binding.topLayout.etView.getText().toString())) {
                    searchName = binding.topLayout.etView.getText().toString();
                    viewModel.getBiddingList(cityNo, typeNo, statusNo, price, false, searchName, areacode, goodsType, sortType, comNo);
                }
                break;
            case R.id.tv_search_delete:
                binding.topLayout.etView.setText("");
                searchName = "";
                viewModel.getBiddingList(cityNo, typeNo, statusNo, price, false, searchName, areacode, goodsType, sortType, comNo);
                break;
            case R.id.tv_category:
                if (null != categoryDatas && categoryDatas.size() > 0) {
                    if (TextUtils.isEmpty(goodsTypeName)) {
                        goodsTypeName = "类别";
                    }
                    updateChooseTextStatus(binding.tvCategory, TextUtils.isEmpty(goodsType) ? -1 : -2, goodsTypeName);
                    if ("0".equals(getArguments().get(FROM_WHERE))) {
                        EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
                        new Handler().postDelayed(() -> categoryFilterPopWindow.showPopwindow(binding.tvCategory, 0, 0), 300);
                    } else {
                        categoryFilterPopWindow.showPopWindow1(binding.tvCategory);
                    }
                    if (!TextUtils.isEmpty(typeNo)) {
                        categoryFilterPopWindow.setData2(categoryDatas.get(tabTypePosition).getChildren(), Integer.valueOf(typeNo), typeDatas.get(tabPosition).getProjectscale(), tabTypePosition);
                    }
                    int pos1 = getItemPos(PickCateType.TYPE_CATEGORY_0);
                    int pos2 = getItemPos(PickCateType.TYPE_CATEGORY_1);
                    int pos3 = getItemPos(PickCateType.TYPE_CATEGORY_2);
                    categoryFilterPopWindow.setCateData(pos1, pos2, pos3);
                }
                break;
            case R.id.tv_location: //手动定位
            case R.id.hand_location:
                //手动定位--不能获取位置信息时
                Intent intent = new Intent();
                intent.setClass(getActivity(), SelectAddressActivity.class);
                intent.putExtra(SelectAddressActivity.TITLE, "我的位置");
                intent.putExtra(SelectAddressActivity.SAVE_TEXT, "使用该定位地址");
                intent.putExtra(SelectAddressActivity.SHOWLOCATION, "SHOWLOCATION");
                intent.putExtra(SelectAddressActivity.LATITUDE, latitude);
                intent.putExtra(SelectAddressActivity.LONGTITUDE, longitude);
                startActivityForResult(intent, 255);

                mapBiddingPopWindowDismiss();

                binding.getLocation.setBackgroundResource(R.drawable.map_text_bg_gray);
                binding.getLocation.setTextColor(getResources().getColor(R.color.color_999999));
                binding.handLocation.setBackgroundResource(R.drawable.map_text_bg_blue);
                binding.handLocation.setTextColor(getResources().getColor(R.color.color_5792FD));

                break;
            case R.id.get_location:
                isLocation = true;
                //重新获取定位--不能获取位置信息时
                if (!isLocationEnabled()) {
                    Intent intent1 = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(intent1);
                } else {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                            ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        PermissionsUtil.requestPermission(getActivity(), new PermissionListener() {
                            @Override
                            public void permissionGranted(@NonNull String[] permissions) {
                                binding.relNoMap.setVisibility(View.GONE);
                                binding.relLocation.setVisibility(View.VISIBLE);
                                isMap = true;
                                initFilterData();
                            }

                            @Override
                            public void permissionDenied(@NonNull String[] permissions) {
                                MToast.showLongToast(getActivity(), "请先允许“经营帮”获取此设备的位置信息");
                            }
                        }, android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION);
                    }
                }
                break;
            case R.id.img_back_top:
                binding.imgBackTop.setVisibility(View.GONE);
                binding.scrollview.smoothScrollTo(0, 0);
                binding.scrollview.scrollTo(0, 0);
                break;
            case R.id.iv_choose:
                if (!TextUtils.isEmpty(typeNo)) {
                    mFilters.put(PickCateType.TYPE_CATEGORY_0, tabTypePosition);
                    mLeftDialog2.initCategory(Integer.parseInt(typeNo), isMap, true);
                    mLeftDialog2.initData(mData, mFilters);
                    mLeftDialog2.showDialog();
                }
                break;
            case R.id.tv_sort:
                showSortPopWindow();
                break;
            case R.id.iv_location_right:
                if (latitude != 0 && longitude != 0) {
                    LatLng latLng = new LatLng(latitude, longitude);
                    binding.mMapView.zoomToSpan(latLng);
                }
                break;
            case R.id.survey_view:
                binding.surveyView.setImageResource(R.drawable.btn_shop_up);
                pickTabLayoutPopWindow.showPopwindow(binding.surveyView);
                pickTabLayoutPopWindow.setData(tabTypeList, binding.tabLayoutType.getSelectedTabPosition());
                break;
            case R.id.iv_quick_entry:
                EventBus.getDefault().postSticky(new QuickEntryEvent(binding.ivQuickEntry, new BackResultContentListener() {
                    @Override
                    public boolean backResult(QuickEntryEntity entity) {
                        switch (entity.getId()) {
                            case "2-3": //直接竞价
                                return true;
                            default:
                                getActivity().finish();
                                return false;
                        }
                    }
                }));
                break;
        }
    }

    public void showList(List<TenderAllListNewEntity> list, boolean isLoadMore) {
        isSearching = false;
        binding.swipeRefresh.finishLoadMore(true);
        if (!TextUtils.isEmpty(searchName) && !isLoadMore) {
            binding.imgBackTop.setVisibility(View.GONE);
            binding.scrollview.smoothScrollTo(0, 0);
            binding.scrollview.scrollTo(0, 0);
        }
        if (list != null) {
            isEnableLoadMore = list.size() >= 10;
        }
        if (isLoadMore) {
            if (list != null && !list.isEmpty()) {
                pickingAdapter.addDatas(list);
            }
        } else {
            if (list != null && !list.isEmpty()) {
                binding.emptyView.setVisibility(View.GONE);
                binding.recyclerView.setVisibility(View.VISIBLE);
                pickingAdapter.setDatas(list);
            } else {
                pickingAdapter.setDatas(new ArrayList<>());
                binding.recyclerView.setVisibility(View.GONE);
                binding.emptyView.setVisibility(View.VISIBLE);
            }
        }
        pickingAdapter.notifyDataSetChanged();

        pickingAdapter.setOnItemClick(new AdapterOnItemClick<TenderAllListNewEntity>() {
            @Override
            public void onItemClick(TenderAllListNewEntity tenderAllListNewEntity, int position) {
                viewModel.getUrlSetting(tenderAllListNewEntity.getId());
            }
        });
        pickingAdapter.onIChildClick(new PickHallAllNewAdapter.IChildClick() {
            @Override
            public void onClick(TenderAllListNewEntity tenderAllListNewEntity) {
                viewModel.getUrlSetting(tenderAllListNewEntity.getId());
            }
        });
    }

    private void mapBiddingPopWindowDismiss() {
        if (pickMapBiddingPopWindow != null && pickMapBiddingPopWindow.isShowing()) {
            pickMapBiddingPopWindow.dismiss();
        }
    }

    public void showMapList(List<BiddingEntity> biddingEntityList, boolean b) {

        if (!b) {
            if (biddingEntityList == null || biddingEntityList.size() == 0) {
                mapBiddingPopWindowDismiss();
                binding.mMapView.updateMarkerDataPick(null, !b);
                return;
            }
            markerEntityList.clear();
        }
        binding.emptyView.setVisibility(View.GONE);
        for (BiddingEntity entity : biddingEntityList) {
            if (!TextUtils.isEmpty(entity.getLocalLat()) && !TextUtils.isEmpty(entity.getLocalLng())) {
                LatLng latLng = new LatLng(Double.valueOf(entity.getLocalLat()), Double.valueOf(entity.getLocalLng()));
                MarkerEntity markerEntity;
                if (entity.getState() == 5) {  //废标
                    markerEntity = new MarkerEntity(latLng, R.mipmap.zhao_gray, entity.getId());
                } else {
                    markerEntity = new MarkerEntity(latLng, R.mipmap.ic_map_overlay_jing, entity.getId());
                }
                markerEntity.setStatus(Integer.toString(entity.getState()));
                markerEntityList.add(markerEntity);
            }
        }

        binding.mMapView.updateMarkerDataPick(markerEntityList, !b);
    }

    private void showPositionMap(int position, boolean isShowPopWindow) {
        if (markerEntityList != null && markerEntityList.size() > position) {
            String title = markerEntityList.get(position).getTitle();
            if (title != null) {
                MarkerOptions markerOptions = binding.mMapView.getMapMarkerPick(title);
                if (markerOptions != null) {
                    setMarkerBig(markerOptions.getTitle());
                    if (isShowPopWindow) {
                        showMapPopWindow(position);
                    }
                }
            }
        }
    }

    public void setbiddingListEntityMapList(List<BiddingEntity> datas, boolean faage, int page) {
        if (datas == null || datas.size() == 0) {
            if (!faage) {
                mapBiddingPopWindowDismiss();
            }
            return;
        }
        if (isMap) {
            if (faage) {
                if (datas != null && datas.size() > 0) {
                    if (biddingListEntityMapList.size() < page * 10) {
                        biddingListEntityMapList.addAll(datas);
                    }
                    showPositionMap((page - 1) * 10, true);
                }
            } else {
                biddingListEntityMapList.clear();
                biddingListEntityMapList.addAll(datas);
                if (isFirstEnter) {
                    showPositionMap(0, false);
                }else{
                    setMarkerBig("");
                    isFirstEnter = true;
                }
            }
        }
    }

    private void setDistanceDatas(String[] strings) {
        PickSelectEntity all = new PickSelectEntity();
        all.setNo("1000");
        all.setProjectscale("全部");
        all.setCheck(true);
        List<PickSelectEntity> distanceDates = new ArrayList<>();
        distanceDates.add(0, all);
        for (String s : strings) {
            PickSelectEntity pickSelectEntity = new PickSelectEntity();
            pickSelectEntity.setNo(s);
            pickSelectEntity.setProjectscale(s + "km以内");
            distanceDates.add(pickSelectEntity);
        }
        refreshDataInfo(PickCateType.TYPE_DISTANCE, "距离", distanceDates);
    }

    public void setTimeDatas(List<PickSelectEntity> datas) {
        refreshDataInfo(PickCateType.PUBLISH_TIME, "发布时间", datas);
    }

    public void setPriceDatas(List<PickSelectEntity> datas) {
        refreshDataInfo(PickCateType.TYPE_MONEY, "预算金额", datas);
    }

    public void setTypeDatas(List<PickSelectEntity> datas) {
        if (datas == null) return;
        typeDatas.clear();
        typeDatas.addAll(datas);
        for (int i = 0; i < typeDatas.size(); i++) {
            binding.tabLayout.addTab(binding.tabLayout.newTab());
            binding.tabLayout.getTabAt(i).setCustomView(R.layout.tab_item_text_image_view);

            View view = binding.tabLayout.getTabAt(i).getCustomView();
            TextView tv = view.findViewById(R.id.tv_tab_item);
            ImageView imageView = view.findViewById(R.id.image_tab_item);
            if (i == 0) {
                tv.setTextColor(getResources().getColor(R.color.APPTabColor));
                tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                PickCopyUtils.setImageResources(0, imageView, true, getContext());
            } else {
                PickCopyUtils.setImageResources(i, imageView, false, getContext());
            }
            tv.setText(typeDatas.get(i).getProjectscale());

        }

        if ("1".equals(getArguments().getString(FROM_WHERE)) || "0".equals(getArguments().getString(FROM_WHERE))) {
            binding.tabLayout.getTabAt(1).select(); //默认选中某项放在加载viewpager之后
        } else {
            binding.tabLayout.postDelayed(new Runnable() {
                @Override
                public void run() {
                    binding.tabLayout.getTabAt(0).select(); //默认选中某项放在加载viewpager之后
                }
            }, 5);
        }

    }

    public void setStatusDatas(List<PickSelectEntity> datas) {
//        statusDatas.clear();
//        statusDatas.addAll(datas);
    }

    public void setCityDatas(List<PickSelectEntity> datas) {
        mLeftDialog2.addEntity(PickCateType.TYPE_CITY, datas);
        mLeftDialog2.showDialog();
    }

    public void setChooseItemData(int type, List<PickSelectEntity> data) {
        if (data == null || data.size() == 0) return;
        switch (type) {
            case PickCateType.TYPE_PROVINCE:
                refreshDataInfo(PickCateType.TYPE_PROVINCE, "省份", data);
                break;
            case PickCateType.TYPE_CITY:
                refreshDataInfo(PickCateType.TYPE_CITY, "市区", data);
                break;
        }
    }

    public void setProvinceDatas(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        if (data != null && data.size() > 0) {
            scrData = data;
            mAddressPop.setData(scrData, true);
        } else {
            viewModel.getProvinceData(PickCateType.TYPE_CITY);
        }
    }

    public void setSortDatas(List<PickSelectEntity> datas) {
        sortData.clear();
        sortData.addAll(datas);
    }

    /**
     * 排序
     */
    private void showSortPopWindow() {
        if (TextUtils.isEmpty(sortTypeName)) {
            sortTypeName = "综合排序";
            pickSortPopWindow.setDefItem();
        }
        updateChooseTextStatus(binding.tvSort, Integer.valueOf(sortType) == 1 ? -1 : -2, sortTypeName);
        if ("0".equals(getArguments().get(FROM_WHERE))) {
            EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
            new Handler().postDelayed(() -> pickSortPopWindow.showPopwindow(binding.tvSort, 0, 0), 300);
        } else {
            pickSortPopWindow.showPopwindow0(binding.tvSort);
        }
        pickSortPopWindow.setData(sortData, false);
    }

    /**
     * 距离筛选
     */
    private void showDistancePopWindow() {
        if (TextUtils.isEmpty(distanceName)) {
            distanceName = "距离";
        }
        updateChooseTextStatus(binding.tvDistance, "1000".equals(distance) ? -1 : -2, distanceName);
        pickDistancePopWindow.showPopwindow0(binding.tvDistance);
        int value = getItemPos(PickCateType.TYPE_DISTANCE);
        pickDistancePopWindow.setData(getItemData(PickCateType.TYPE_DISTANCE), value);
    }

    /**
     * 省份
     */
    private void showProvincePopWindow() {
        if (scrData == null) {
            viewModel.getProvinceData(PickCateType.TYPE_PROVINCE);
            return;
        }
        if (TextUtils.isEmpty(areaName)) {
            areaName = "地区";
        }
        updateChooseTextStatus(binding.tvArea, TextUtils.isEmpty(areacode) && TextUtils.isEmpty(cityNo) ? -1 : -2, areaName);
        mAddressPop.showPopwindow0(binding.tvArea);
    }

    /**
     * 预算金额
     */
    private void showMoneyPopWindow() {
        if (TextUtils.isEmpty(priceName)) {
            priceName = "预算金额";
        }
        updateChooseTextStatus(binding.tvMoney, TextUtils.isEmpty(price) ? -1 : -2, priceName);
        if ("0".equals(getArguments().get(FROM_WHERE))) {
            EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
            new Handler().postDelayed(() -> pickMoneyPopWindow.showPopwindow(binding.tvMoney, 0, 0), 300);
        } else {
            pickMoneyPopWindow.showPopwindow0(binding.tvMoney);
        }
        int value = getItemPos(PickCateType.TYPE_MONEY);
        pickMoneyPopWindow.setData(getItemData(PickCateType.TYPE_MONEY), value);
    }

    private void showMapPopWindow(int position) {
        boolean isShowMapPopup = true;
        if (getActivity() instanceof PickHallActivity3) {
            isShowMapPopup = ((PickHallActivity3) getActivity()).isShow("直接竞价");
        }
        if (pickMapBiddingPopWindow != null && isShowMapPopup) {
            if (!pickMapBiddingPopWindow.isShowing() && binding.frameLayoutList.getVisibility() == View.GONE) {
                pickMapBiddingPopWindow.showDownPopwindow(binding.tvDistance, true);
                pickMapBiddingPopWindow.backgroundAlpha(1f);
            }
            pickMapBiddingPopWindow.setData(biddingListEntityMapList, position);

            //点击外部区域不消失
            pickMapBiddingPopWindow.setFocusable(false);
            pickMapBiddingPopWindow.setOutsideTouchable(false);
            pickMapBiddingPopWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            pickMapBiddingPopWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        } else {
            mapBiddingPopWindowDismiss();
        }
    }

    @Override
    public void onInvisible() {
        super.onInvisible();
        mapBiddingPopWindowDismiss();
    }

    public void getUrl(String url, String id) {
        if (TextUtils.isEmpty(url)) return;
        WebViewX5HostActivity.start(getActivity(), url, id);
    }

    private void setTextViewBg(TextView textView, int bg, int img, int textColor) {
        if (getActivity() != null && !getActivity().isFinishing() && !getActivity().isDestroyed()) {
            if (isAdded()) {
                textView.setBackground(getResources().getDrawable(bg));
                Drawable drawable_n = getResources().getDrawable(img);
                drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此为必须写的
                textView.setCompoundDrawables(null, null, drawable_n, null);
                textView.setTextColor(getResources().getColor(textColor));
            }
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == getActivity().RESULT_OK) {
            if (requestCode == 255) {
                if (data == null) {
                    return;
                }

                Double latitudeHand = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0);
                Double longitudeHand = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0);
                String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);

                if (!"地址信息".equals(address)) {
                    binding.tvAddressName.setText(address);
                }

                if (latitude == null && longitude == null) {  //自动定位未获取到位置 第一次
                    if (latitudeHand != 0 || longitudeHand != 0) {  //手动定位获取到位置
                        isHandLocation = true;
                        latitude = latitudeHand;
                        longitude = longitudeHand;
                        binding.relNoMap.setVisibility(View.GONE);
                        binding.relLocation.setVisibility(View.VISIBLE);
                        binding.mMapView.setVisibility(View.VISIBLE);
                        binding.mMapView.setMyLocation(latitude, longitude, R.drawable.location);
                    } else {
                        binding.handLocation.setBackgroundResource(R.drawable.map_text_bg_gray);
                        binding.handLocation.setTextColor(getResources().getColor(R.color.color_999999));
                    }
                } else {
                    if (!latitudeHand.equals(latitude) || !longitudeHand.equals(longitude)) {
                        latitude = latitudeHand;
                        longitude = longitudeHand;
                        binding.mMapView.setMyLocation(latitude, longitude, R.drawable.location);
                    } else {
                        binding.relNoMap.setVisibility(View.GONE);
                    }
                }
                initFilterData();
            }
        }
    }

    //用户是否打开系统定位服务
    public boolean isLocationEnabled() {
        int locationMode = 0;
        String locationProviders;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
            } catch (Settings.SettingNotFoundException e) {
                e.printStackTrace();
                return false;
            }
            return locationMode != Settings.Secure.LOCATION_MODE_OFF;
        } else {
            locationProviders = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
            return !TextUtils.isEmpty(locationProviders);
        }
    }

    private PickChooseLeftDialog2 mLeftDialog2;
    // 数据集
    private SparseArray<PickSelectTextEntity> mData = new SparseArray<>();
    private SparseIntArray mFilters = new SparseIntArray();
    private SparseArray<String> nameArray = new SparseArray<>();

    private void initChooseDialog() {
        nameArray.put(PickCateType.TYPE_CATEGORY_0, "类别");
        nameArray.put(PickCateType.TYPE_CATEGORY_1, "类别1");
        nameArray.put(PickCateType.TYPE_CATEGORY_2, "类别2");
        nameArray.put(PickCateType.PUBLISH_TIME, "发布时间");
        nameArray.put(PickCateType.TYPE_MONEY, "预算金额");
        nameArray.put(PickCateType.TYPE_PROVINCE, "省份");
        nameArray.put(PickCateType.TYPE_CITY, "市区");
        nameArray.put(PickCateType.TYPE_DISTANCE, "距离");
        mLeftDialog2 = new PickChooseLeftDialog2(getActivity(), nameArray);
        mLeftDialog2.setCallBack(this);
    }

    /**
     * 添加数据到中数据聚合
     */
    private void refreshDataInfo(int sort, String name, List<PickSelectEntity> children) {
        clearOtherDataInfo(sort);
        addEntity(sort, children, name);
    }

    /**
     * 清理关联项为空
     */
    private void clearOtherDataInfo(int sort) {
        switch (sort) {
            case PickCateType.TYPE_CATEGORY_0:
                addEntity(PickCateType.TYPE_CATEGORY_1, new ArrayList<>());
                addEntity(PickCateType.TYPE_CATEGORY_2, new ArrayList<>());
                break;
            case PickCateType.TYPE_CATEGORY_1:
                addEntity(PickCateType.TYPE_CATEGORY_2, new ArrayList<>());
                break;
            case PickCateType.TYPE_PROVINCE:
                addEntity(PickCateType.TYPE_CITY, new ArrayList<>());
                break;
        }
    }

    public void addEntity(int index, List<PickSelectEntity> list) {
        if (mData.get(index) != null) {
            if (list == null || list.size() == 0) {
                mData.get(index).setPickSelectEntityList(new ArrayList<>());
            } else {
                mData.get(index).setPickSelectEntityList(list);
            }
        } else {
            mData.put(index, new PickSelectTextEntity(index, nameArray.get(index), list));
        }
        mFilters.put(index, 0);
    }

    public void addEntity(int index, List<PickSelectEntity> list, String name) {
        if (mData.get(index) != null) {
            if (list == null || list.size() == 0) {
                mData.get(index).setPickSelectEntityList(new ArrayList<>());
            } else {
                mData.get(index).setPickSelectEntityList(list);
            }
            mData.get(index).setTypeName(name);
        } else {
            mData.put(index, new PickSelectTextEntity(index, name, list));
        }
        mFilters.put(index, 0);
    }

    @Override
    public void loadCategory(PickSelectTextEntity entity, int itemPos) {
        List<PickSelectEntity> children = new ArrayList<>();
        if (itemPos > 0) {
            switch (entity.getSort()) {
                case PickCateType.TYPE_CATEGORY_0:
                    if (categoryDatas == null || categoryDatas.size() == 0) {
                        return;
                    }
                    List<PickSelectEntity<List<PickSelectEntity>>> cate1 = categoryDatas.get(itemPos).getChildren();
                    if (cate1 != null && cate1.size() > 0) {
                        children.addAll(cate1);
                    }
                    mLeftDialog2.clearOtherDataInfo(entity.getSort());
                    mLeftDialog2.addEntity(PickCateType.TYPE_CATEGORY_1, children);
                    mLeftDialog2.showDialog();
                    break;
                case PickCateType.TYPE_CATEGORY_1:
                    if (categoryDatas == null || categoryDatas.size() == 0) {
                        return;
                    }
                    int firPos = mLeftDialog2.getItemPos(0);
                    List<PickSelectEntity> cate2 = categoryDatas.get(firPos).getChildren().get(itemPos).getChildren();
                    if (cate2 != null && cate2.size() > 0) {
                        children.addAll(cate2);
                    }
                    mLeftDialog2.clearOtherDataInfo(entity.getSort());
                    mLeftDialog2.addEntity(PickCateType.TYPE_CATEGORY_2, children);
                    mLeftDialog2.showDialog();
                    break;
                case PickCateType.TYPE_PROVINCE:
                    String itemNo = entity.getItemNo(itemPos);
                    viewModel.getAddressCityDataDialog(scrData, itemNo);
                    break;
            }
        } else {
            if (entity.getSort() == PickCateType.TYPE_CATEGORY_0 || entity.getSort() == PickCateType.TYPE_CATEGORY_1 || entity.getSort() == PickCateType.TYPE_PROVINCE) {
                mLeftDialog2.clearOtherDataInfo(entity.getSort());
                mLeftDialog2.showDialog();
            }
        }

    }

    @Override
    public void loadData(SparseArray<PickSelectTextEntity> data, SparseIntArray map) {
        mData = PickCopyUtils.deepCopy(data);
        mFilters = map.clone();
        if (mFilters.size() > 0 && mFilters.get(0) > 0) {
            isDialogData = true;
            binding.tabLayoutType.getTabAt(mFilters.get(0)).select();
        }
        for (int i = 0; i < mData.size(); i++) {
            int key = mData.keyAt(i);
            PickSelectTextEntity entity = mData.get(key);
            updateChooseStatus(entity.getSort(), mFilters.get(entity.getSort()));
        }
        initFilterData();
    }

    @Override
    public void reset() {
        mFilters.clear();
        clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
        clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
        loadData(mData, mFilters);
        mLeftDialog2.initData(mData, mFilters);
        mLeftDialog2.showDialog();
        if (binding.tabLayoutType.getTabAt(0) != null) {
            binding.tabLayoutType.getTabAt(0).select();
        }
    }

    @Override
    public void onCancel() {
        mLeftDialog2.initData(mData, mFilters);
    }

    /**
     * 获取当前缓存位置下标
     *
     * @param pos index
     */
    public int getItemPos(int pos) {
        return mFilters.get(pos);
    }

    public List<PickSelectEntity> getItemData(int index) {
        if (mData.get(index) != null) {
            return mData.get(index).getPickSelectEntityList();
        }
        return new ArrayList<>();
    }

    /**
     * 筛选赋值
     */
    private void updateChooseStatus(int key, int value) {
        mFilters.put(key, value);
        String no = mData.get(key).getItemNo(value);
        String name = mData.get(key).getItemName(value);
        switch (key) {
            case PickCateType.TYPE_CATEGORY_0:  //类别
            case PickCateType.TYPE_CATEGORY_1:
                if (TextUtils.isEmpty(no)) {
                    goodsTypeName = "类别";
                } else {
                    goodsType = no;
                    goodsTypeName = name;
                }
                updateChooseTextStatus(binding.tvCategory, value, goodsTypeName);
                break;
            case PickCateType.TYPE_CATEGORY_2:
                if (!TextUtils.isEmpty(no)) {
                    goodsType = no;
                    goodsTypeName = name;
                    if (value > 0) {
                        updateChooseTextStatus(binding.tvCategory, value, goodsTypeName);
                    }
                }
                break;
            case PickCateType.TYPE_MONEY: // 预算金额
                price = no;
                priceName = name;
                updateChooseTextStatus(binding.tvMoney, value, name);
                break;
            case PickCateType.TYPE_PROVINCE: // 省
                areacode = no;
                mAddressPop.setDefPosition(value, 0);
                if (value == 0) {
                    areaName = "地区";
                } else {
                    areaName = name;
                }
                updateChooseTextStatus(binding.tvArea, value, areaName);
                break;
            case PickCateType.TYPE_CITY: // 城市
                cityNo = no;
                mAddressPop.setDefPosition(mFilters.get(PickCateType.TYPE_PROVINCE), value);
                if (value > 0) {
                    areaName = name;
                    updateChooseTextStatus(binding.tvArea, value, areaName);
                }
                break;
            case PickCateType.TYPE_DISTANCE: // 距离
                distance = no;
                distanceName = name;
                if (value > 0) {
                    updateChooseTextStatus(binding.tvDistance, value, name);
                }
                break;
        }
    }

    /**
     * 更新选项颜色
     */
    private void updateChooseTextStatus(PickPopWindowView pickPopWindowView, int value, String name) {
        if (!TextUtils.isEmpty(name)) {
            if (name.length() > 4) {
                name = name.substring(0, 4) + "...";
            }
        }
        if (value == -1 || value == -2) {
            binding.popLine.setVisibility(View.VISIBLE);
            pickPopWindowView.setChooseData(R.drawable.member_pop_blue_bg2, R.mipmap.ic_up_arrow_n, R.color.color_333333, true, name);
        } else if (value == 0) {
            binding.popLine.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333, false, name);
        } else {
            binding.popLine.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_new_blue_bg_10, R.mipmap.icon_down_red, R.color.color_main, false, name);
        }
    }

    private void showChooseView(int tabPos) {
        if (isMap) {
            binding.tvSort.setVisibility(View.GONE);
            binding.tvMoney.setVisibility(View.VISIBLE);
            binding.tvArea.setVisibility(View.GONE);
            binding.tvDistance.setVisibility(View.VISIBLE);
        } else {
            if (tabPos == 0) {
                if (mData != null && mData.size() > 0 && mData.get(0) != null) {
                    if (mData.get(0).getTypeName().contains("类别")) {
                        mData.remove(0);
                    }
                }
                binding.tvArea.setVisibility(View.VISIBLE);
            } else {
                binding.tvArea.setVisibility(View.GONE);
            }
            binding.tvMoney.setVisibility(View.VISIBLE);
            binding.tvSort.setVisibility(View.VISIBLE);
            binding.tvDistance.setVisibility(View.GONE);
        }
    }

    public void updateData(String text) {
        searchName = text;
        isFirstEnter = false;
        initFilterData();
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(MaterialEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_EXPANDED) {
            if (layoutParams != null) {
                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                binding.llContainer.setLayoutParams(layoutParams);
                isParentAppBarCollapsed = false;
            }
        } else if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_COLLAPSED) {
            if (layoutParams != null) {
//                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
//                binding.llContainer.setLayoutParams(layoutParams);
                isParentAppBarCollapsed = true;
            }
        } else if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_COMMON) {
            if (layoutParams != null) {
                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                binding.llContainer.setLayoutParams(layoutParams);
                isParentAppBarCollapsed = false;
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void jumpLogin() {
        boolean shanyan = MkvUtils.get().getBoolean(MkvUtils.CommomData, CacheMarker.ShanYan, false);
        if (shanyan) {
            //校验权限
            //申请动态权限
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //6.0以上运行时权限处理
                EsayPermissions.with(getActivity()).constantRequest().permission(PERMISSIONS).request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        openLoginPage();
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        openLoginPage();
                    }
                });

            } else {
                //有权限
                openLoginPage();
            }

        } else {
            VerificationCodeLoginActivity.start(getContext(), EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        }
    }

    //闪验
    static final String[] PERMISSIONS = new String[]{
            Manifest.permission.READ_PHONE_STATE
    };

    /**
     * 拉起授权页
     */
    private void openLoginPage() {
        //设置授权页样式
        OneKeyLoginManager.getInstance().setAuthThemeConfig(ConfigUtils.getCJSConfig(getContext()));
        //开始拉取授权页
        DialogHelper.showProgressDialog(getContext(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(true);
        OneKeyLoginManager.getInstance().openLoginAuth(false, new OpenLoginAuthListener() {
            @Override
            public void getOpenLoginAuthStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code != 1000) {
                    VerificationCodeLoginActivity.start(getContext(), EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
                }
            }
        }, new OneKeyLoginListener() {
            @Override
            public void getOneKeyLoginStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code == 1000) {
                    OneKeyLoginEntity oneKeyLoginEntity = GsonManager.getInstance().getGson().fromJson(result, OneKeyLoginEntity.class);
                    oneKeyLoginEntity.setPlateform("Android");
                    viewModel.oneKeyLogin(oneKeyLoginEntity);
                }
            }
        });
    }

    /**
     * 一键登录成功
     *
     * @param loginEntity
     * @param phoneNumber
     */
    public void loginSucceed(LoginEntity loginEntity, String phoneNumber) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageData(phoneNumber);
        loginEvent.setMessageTag(EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        loginEvent.setObject(loginEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

    public void getUserMsgSucceed(UserMsgEntity userMsgEntity) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageTag(EventConstant.EVENT_USER_MSG);
        loginEvent.setMessageData(userMsgEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

}